<template>
	<view>
		<u-tabs 
			:list="tabsList" 
			active-color="#849ee3" 
			inactive-color="#606266" 
			:is-scroll="false" 
			:current="current"
			@change="tabChange">
		</u-tabs>
		
		<view class="container u-relative" style="top: 78rpx;">
			<wx-load-more ref="loadMore" @provider="provider" @resData="resData" :dataLists="dataList" :pageSize="20">
				<template v-slot:list="{ items,datas }">
					<block v-for="(item,index) in datas" :key="index">
						<view class="u-flex z-b-r white-bg u-padding-20 u-margin-bottom-20">
							<!-- <view class="u-margin-bottom-10">
								<u-tag :text="item.signinStatus === 0 ? '等待审核' : (item.signinStatus === 1 ? '审核通过' : '审核未通过')" :type="item.signinStatus === 0 ? 'info' : (item.signinStatus === 1 ? 'success' : 'warning')"
								 shape="circle" />
							</view> -->
							<view class="u-flex-1">
								<view class="u-margin-bottom-10">
									<text>钻孔深度：{{ item.hole_deep }}</text>
								</view>
								<view class="u-margin-bottom-10">
									<text>孔号：{{ item.hole_mark }}</text>
								</view>
								<view class="u-margin-bottom-10">
									<text>打卡日期：{{ item.date }}</text>
								</view>
							</view>
							<view class="u-margin-right-20 u-flex" v-if="item.signinStatus === 0">
								<view><u-tag @click="checkHandle(item,1,index)" text="通过" type="success"/></view>
								<view class="u-padding-20">|</view>
								<view><u-tag @click="checkHandle(item,-1,index)" text="拒绝" type="error"/></view>
							</view>
						</view>
					</block>
				</template>
			</wx-load-more>
		</view>
		<!-- 消息提示 -->
		<u-toast ref="uToast" />
		<u-modal v-model="showModel" @confirm="confirmRejectSign" show-cancel-button="true" content="是否确认拒绝该员工打卡"></u-modal>
	</view>
</template>

<script>
	import wxLoadMore from '../../../components/wx-load-more/wx-load-more.vue';
	export default {
		data() {
			return {
				showModel:false,
				projectID:"",
				tabsList: [{
					name: '待审核',
					id:0
				}, {
					name: '已通过',
					id:1
				}, {
					name: '未通过',
					id:-1
				}],
				current: 0,
				disposeItem:{},
				disposeStatus:0,
				disposeIndex:-1,
				dataList:[]
			}
		},
		components:{
			wxLoadMore
		},
		onLoad(params) {
			this.projectID = params.projectID;
		},
		mounted() {
			this.$refs.loadMore.reLoadData();
		},
		onReachBottom() {
			this.$refs.loadMore.reachBottom()
		},
		methods: {
			async checkHandle(item,status,index){
				this.disposeItem = item;
				this.disposeStatus = status;
				this.disposeIndex = index;
				if(status === -1){
					this.showModel = true;
				} else if(status === 1){
					this.sendCheckResult()
				}
			},
			confirmRejectSign(){
				this.sendCheckResult()
			},
			async sendCheckResult(){
				let {disposeItem,disposeStatus,token,projectID,disposeIndex} = this;
				this.$loading("正在处理")
				let res = await this.$network({
					api:"main",
					data:{
						action:"signAudit/pmUploadCheckResult",
						data:{
							token,
							_id:disposeItem._id,
							signinStatus:disposeStatus,
							drillDeep:parseFloat(disposeItem.hole_deep),
							projectID,
							wkID:disposeItem.wkID,
							holeNum:disposeItem.hole_mark
						}
					}
				})
				
				uni.hideLoading()
				if(res.status === 0){
					this.dataList.splice(disposeIndex,1);
					this.$refs.uToast.show({
						title: '处理成功',
						type: 'success'
					})
				}
			},
			tabChange(index){
				this.current = index;
				//切换的时候 重新加载
				this.$refs.loadMore.reLoadData();
			},
			resData(d){
				this.dataList = d;
			},
			async provider(e) {
				let {pageNo,pageSize} = e;
				let {token,projectID,current} = this;
				
				this.$loading("正在加载")
				let res = await this.$network({
					api: "main",
					data: {
						action:"signAudit/getSignInof",
						data:{
							token,
							projectID,
							pageNo,
							pageSize,
							signinStatus:this.tabsList[current].id
						}
					}
				})
				uni.hideLoading();
				if (res.status === 0) {
					this.$refs.loadMore.pushData(res.data);
				} else if(res.status === 1) {
					this.$refs.loadMore.pushData([]);
				}
			}
		}
	}
</script>

<style>

</style>
